package localizer.main;


import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

public class Menuable extends Activity {
    /** Called when the activity is first created. */
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.main);
    }
    
    @Override
    public void onAttachedToWindow() {
    	super.onAttachedToWindow();
        openOptionsMenu(); 
    };
    
    @Override
    protected void onStop(){
    	openOptionsMenu(); 
    	super.onStop();
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {    
    	MenuInflater inflater = getMenuInflater();    
    	inflater.inflate(R.layout.menu, menu);
    	return true;
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {    // Handle item selection    
    	switch (item.getItemId()) {        
			case R.id.menu_preferences: 
				startActivity(new Intent(this, TableActivity.class));
				return true;      
			case R.id.menu_help:
				Intent hintent = new Intent(this,HelpActivity.class);
				startActivity(hintent);
				return true;
			case R.id.menu_last_loc:
				Intent lintent = new Intent(this,MapAppActivity.class);
				startActivity(lintent);
				return true;
			case R.id.menu_quit:         
				finish();
				return true;
			case R.id.menu_ring:
				Intent rintent = new Intent(this,ContactPicker.class);
				rintent.putExtra("tipe", "ring");
				startActivity(rintent);
				return true;
			case R.id.menu_ring_silent:
				Intent rintent2 = new Intent(this,ContactPicker.class);
				rintent2.putExtra("tipe", "silent");
				startActivity(rintent2);
				return true;
			case R.id.menu_loc:
				Intent rintent3 = new Intent(this,ContactPicker.class);
				rintent3.putExtra("tipe", "loc");
				startActivity(rintent3);
				return true; 
				
			case R.id.menu_internet:
				String url = LoginActivity.SITE;
				Intent i = new Intent(Intent.ACTION_VIEW);
				i.setData(Uri.parse(url));
				startActivity(i);
				return true;
			default:            
				return super.onOptionsItemSelected(item);    
		}
    }
}